package com.yxq.mdt.app.modules.bottomsheet;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.alibaba.android.arouter.utils.TextUtils;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import com.yxq.mdt.app.R;
import com.yxq.mdt.app.modules.publish.ui.activity.PublishImageActivity;
import com.yxq.mdt.app.modules.publish.ui.activity.PublishVideoActivity;
import com.yxq.mdt.app.modules.publish.ui.activity.PublishVoiceActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import q.rorbin.badgeview.DisplayUtil;

import static android.app.Activity.RESULT_OK;

/**
 * 发布弹窗
 */
public class PublishBottomSheetFragment extends BottomSheetDialogFragment {
    Unbinder unbinder;
    @BindView(R.id.publish_img)
    LinearLayout publishImg;
    @BindView(R.id.publish_video)
    LinearLayout publishVideo;
    @BindView(R.id.publish_record)
    LinearLayout publishRecord;
    @BindView(R.id.publish_cancel)
    ImageView publishCancel;
    @BindView(R.id.publish_relative)
    RelativeLayout publishRelative;
    @BindView(R.id.publish_lint)
    LinearLayout publishLint;
    String topic = "请选择话题", groupId = "";

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(BottomSheetDialogFragment.STYLE_NORMAL, R.style.CustomBottomSheetDialogTheme);

    }

    public PublishBottomSheetFragment(String s, String id) {
        this.topic = s;
        this.groupId = id;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.publish_bottom_sheet_fragment, container, false);
        unbinder = ButterKnife.bind(this, view);
        initViews();
        return view;
    }


    public void initViews() {
        ViewGroup.LayoutParams params = publishRelative.getLayoutParams();
        params.height = DisplayUtil.dp2px(getContext(), 240);
        publishRelative.setLayoutParams(params);

    }

    @Override
    public void onStart() {
        super.onStart();

    }

    @OnClick({R.id.publish_lint, R.id.publish_img, R.id.publish_video, R.id.publish_record, R.id.publish_cancel, R.id.publish_relative})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.publish_lint:
                dismiss();
                break;
            //发布图片
            case R.id.publish_img:
                if (TextUtils.isEmpty(topic)) {
                    Intent intentImage = new Intent(getContext(), PublishImageActivity.class);
                    startActivity(intentImage);
                } else {
                    Intent intentImage = new Intent(getContext(), PublishImageActivity.class);
                    intentImage.putExtra("topic", topic);
                    intentImage.putExtra("CircleId", groupId);
                    intentImage.putExtra("CircleName", topic);
                    startActivity(intentImage);
                }

                dismiss();
                break;
            //发布视频
            case R.id.publish_video:
                if (TextUtils.isEmpty(topic)) {
                    Intent intentVideo = new Intent(getContext(), PublishVideoActivity.class);
                    startActivity(intentVideo);
                } else {
                    Intent intentVideo = new Intent(getContext(), PublishVideoActivity.class);
                    intentVideo.putExtra("CircleId", groupId);
                    intentVideo.putExtra("topic", topic);
                    intentVideo.putExtra("CircleName", topic);
                    getActivity().startActivityForResult(intentVideo, 100);
                }
                dismiss();
                break;
            //发布语音
            case R.id.publish_record:
                if (TextUtils.isEmpty(topic)) {
                    Intent intentVoice = new Intent(getContext(), PublishVoiceActivity.class);
                    startActivity(intentVoice);
                } else {
                    Intent intentVoice = new Intent(getContext(), PublishVoiceActivity.class);
                    intentVoice.putExtra("CircleId", groupId);
                    intentVoice.putExtra("topic", topic);
                    intentVoice.putExtra("CircleName", topic);
                    getActivity().startActivityForResult(intentVoice, 100);
                }
                dismiss();
                break;
            case R.id.publish_cancel:
                dismiss();
                break;
            case R.id.publish_relative:
                dismiss();
                break;
        }
    }
}
